﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DoAn_BumTruong_DesignPattern.Admin
{
    public partial class Comments : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        Facades fccomment = new Facades();
        private void LoadData()
        {
            int howManyPage = 0;
            string page = Request.QueryString["Page"] ?? "1";
            string fistPageUrl = Link.ToComment("1");
            string pageUrl = Link.ToComment("{0}");
            RepeaterComment.DataSource = fccomment.PagingComment(page, out howManyPage);
            RepeaterComment.DataBind();
            PagesButton.ShowPage(int.Parse(page), howManyPage, fistPageUrl, pageUrl, true);
        }

        protected override void OnInitComplete(EventArgs e)
        {
            base.OnInitComplete(e);
            RepeaterComment.ItemCommand += RepeaterComment_ItemCommand;
        }

        void RepeaterComment_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "UpdateActive")
            {
                string[] arr = e.CommandArgument.ToString().Split('_');
                if(fccomment.UpdateShowHide(int.Parse(arr[0]), !Convert.ToBoolean(arr[1])))
                    LoadData();
            }
        }
    }
}